var ressClass = {'Лесопилка': 'r1',
                'Глиняный карьер':'r2',
                'Железный рудник':'r3',
                'Ферма':'r4'};

var db = new DB();
var resources = new Resources();

hoho();

function hoho() {
    var map_details = $('#map_details');
    var nipalicaTable = $('<table id="nipalicaTable"><tr><td colspan="2"></td></tr></table>');

    var areas = $('#rx').children('area');//.sort(function(a,b){ return a.title - b.title});
    var villageType = db.getVillageType($('#village_map').attr('class'));

    jQuery.each(areas, function(index, value) {
        addRowToNipalicaTable(nipalicaTable, value, villageType[index]);
    });

    alert(resources.getValue(0));

    removeMap();
    $('#map_details').remove();
    var contentTable = $('<table><tr><td>' + nipalicaTable.html() + '</td></tr></table>');
    $('#vlist').after(map_details);
    $('#content h1').after(contentTable);

}

function addRowToNipalicaTable(table, area, resourceType) {
    var mineInfo = area.title.split(' ');
    var mineLevel = mineInfo[mineInfo.length - 1];
    var tr = '<tr>';
    tr += '<td>';
    tr += '<img class="' + db.getResourceClass(resourceType) + '" src="img/x.gif"/>';
    tr += '<a href="' + area.href + '" title="' + area.title + '">' + mineLevel + '</a>';
    tr += '</td>';
    tr += '</tr>';
    table.append(tr);
}

function removeMap() {
    $('#rx').remove();
    $('#village_map').remove();
}

function Resources() {

    var resourceValueRowIds = {0: 'l4',
                1:'l3',
                2:'l2',
                3:'l1'
    };

    var resources = new Array();

    for (var i = 0; i < 4; i++) {
        resources[i] = getResource(i);
    }

    this.getPerHour = function(resourceType) {
        return resources[resourceType][0];
    };

    this.getValue = function(resourceType) {
        return resources[resourceType][1];
    };

    this.getLimit = function(resourceType) {
        return resources[resourceType][2];
    };

    function getResource(resourceType) {
        var resourceElement = $('#' + resourceValueRowIds[resourceType]);
        var perHour = resourceElement.attr('title');
        var value   = resourceElement.text().split('/')[0];
        var limit   = resourceElement.text().split('/')[1];
        return [perHour, value, limit];
    }
}

// classes

function DB()  {

    this.wood = 0;
    this.clay = 1;
    this.iron = 2;
    this.crop = 3;

    this.getVillageType = function(type) {
        return villageType[type];
    };

    this.getResourceClass = function(resourceType) {
        return resourceClass[resourceType];
    };

    this.getBuildCost = function(buildingType, lvl, resourceType) {
        return resourceType ? buildCost[buildingType][lvl][resourceType] : buildCost[buildingType][lvl];
    };

    var villageType = { // 0 - wood, 1 - clay, 2 - iron, 3 - crop
			'f1':  [3, 3, 0, 3, 3, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1], //9 crop
			'f2':  [2, 3, 0, 2, 1, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1],
			'f3':  [0, 3, 0, 2, 1, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1], //4-4-4-6
			'f4':  [0, 3, 0, 1, 1, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1],
			'f5':  [0, 3, 0, 2, 0, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1],
			'f6':  [3, 3, 0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3], //15 crop
			'f7':  [0, 3, 3, 0, 1, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1], //4-4-3-7
			'f8':  [2, 3, 3, 0, 1, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1], //3-4-4-7
			'f9':  [2, 3, 3, 0, 0, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1], //4-3-4-7
			'f10': [2, 3, 0, 1, 1, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1], //3-5-4-6
			'f11': [2, 0, 0, 2, 0, 3, 3, 2, 2, 1, 1, 2, 0, 3, 3, 1, 3, 3], //4-3-5-6
			'f12': [0, 3, 0, 0, 1, 1, 2, 3, 3, 2, 2, 3, 3, 0, 3, 1, 0, 1]  //5-4-3-6
    };

    var resourceClass = {wood: 'r1',
                clay:'r2',
                iron:'r3',
                crop:'r4'
    };


    var buildCost = [

        [//lumberCost gid = 1
            [0,0,0,0,0,0],
            [40,100,50,60,1,2],
            [65,165,85,100,1,3],
            [110,280,140,165,2,4],
            [185,465,235,280,2,5],
            [310,780,390,465,2,6],
            [520,1300,650,780,3,8],
            [870,2170,1085,1300,4,10],
            [1450,3625,1810,2175,4,12],
            [2420,6050,3025,3630,5,14],
            [4040,10105,5050,6060,6,16],//10
            [6750,16870,8435,10125,7,18],
            [11270,28175,14090,16905,9,20],
            [18820,47055,23525,28230,11,22],
            [31430,78580,39290,47150,13,24],
            [52490,131230,65615,78740,15,26],
            [87660,219155,109575,131490,18,29],
            [146395,365985,182995,219590,22,32],
            [244480,611195,305600,366715,27,35],
            [408280,1020695,510350,612420,32,38],
            [681825,1704565,852280,1022740,38,41],//20
            [1138650,2846620,1423310,1707970,38,44],
            [1901540,4753855,2376925,2852315,38,47],
            [3175575,7938935,3969470,4763360,38,50],
            [5303210,13258025,6629015,7954815,38,53],
            [8856360,22140900,11070450,13284540,38,56]//25
        ],
        [//clayCost gid = 2
            [0,0,0,0,0,0],
            [80,40,80,50,1,2],
            [135,65,135,85,1,3],
            [225,110,225,140,2,4],
            [375,185,375,235,2,5],
            [620,310,620,390,2,6],
            [1040,520,1040,650,3,8],
            [1735,870,1735,1085,4,10],
            [2900,1450,2900,1810,4,12],
            [4840,2420,4840,3025,5,14],
            [8080,4040,8080,5050,6,16],//10
            [13500,6750,13500,8435,7,18],
            [22540,11270,22540,14090,9,20],
            [37645,18820,37645,23525,11,22],
            [62865,31430,62865,39290,13,24],
            [104985,52490,104985,65615,15,26],
            [175320,87660,175320,109575,18,29],
            [292790,146395,292790,182995,22,32],
            [488955,244480,488955,305600,27,35],
            [816555,408280,816555,510350,32,38],
            [1363650,681825,1363650,852280,38,41],//20
            [2277295,1138650,2277295,1423310,38,44],
            [3803085,1901540,3803085,2376925,38,47],
            [6351150,3175575,6351150,3969470,38,50],
            [10606420,5303210,10606420,6629015,38,53],
            [17712720,8856360,17712720,11070450,38,56]//25
        ],
        [//ironCost gid = 3
            [0,0,0,0,0,0],
            [100,80,30,60,1,3],
            [165,135,50,100,1,5],
            [280,225,85,165,2,7],
            [465,375,140,280,2,9],
            [780,620,235,465,2,11],
            [1300,1040,390,780,3,13],
            [2170,1735,650,1300,4,15],
            [3625,2900,1085,2175,4,17],
            [6050,4840,1815,3630,5,19],
            [10105,8080,3030,6060,6,21],//10
            [16870,13500,5060,10125,7,24],
            [28175,22540,8455,16905,9,27],
            [47055,37645,14115,28230,11,30],
            [78580,62865,23575,47150,13,33],
            [131230,104985,39370,78740,15,36],
            [219155,175320,65745,131490,18,39],
            [365985,292790,109795,219590,22,42],
            [611195,488955,183360,366715,27,45],
            [1020695,816555,306210,612420,32,48],
            [1704565,1363650,511370,1022740,38,51],//20
            [2846620,2277295,853985,1707970,38,54],
            [4753855,3803085,1426155,2852315,38,57],
            [7938935,6351150,2381680,4763360,38,60],
            [13258025,10606420,3977410,7954815,38,63],
            [22140900,17712720,6642270,13284540,38,66]//25
        ],
        [//cropCost gid = 4
            [0,0,0,0,0,0],
            [70,90,70,20,1,0],
            [115,150,115,35,1,0],
            [195,250,195,55,2,0],
            [325,420,325,95,2,0],
            [545,700,545,155,2,0],
            [910,1170,910,260,3,1],
            [1520,1950,1520,435,4,2],
            [2535,3260,2535,725,4,3],
            [4235,5445,4235,1210,5,4],
            [7070,9095,7070,2020,6,5],//10
            [11810,15185,11810,3375,7,6],
            [19725,25360,19725,5635,9,7],
            [32940,42350,32940,9410,11,8],
            [55005,70720,55005,15715,13,9],
            [91860,118105,91860,26245,15,10],
            [153405,197240,153405,43830,18,12],
            [256190,329385,256190,73195,22,14],
            [427835,550075,427835,122240,27,16],
            [714485,918625,714485,204140,32,18],
            [1193195,1534105,1193195,340915,38,20],//20
            [1992635,2561960,1992635,569325,38,22],
            [3327700,4278470,3327700,950770,38,24],
            [5557255,7145045,5557255,1587785,38,26],
            [9280620,11932225,9280620,2651605,38,28],
            [15498630,19926810,15498630,4428180,38,30]//25
        ],
        [//sawmillCost gid = 5
            [0,0,0,0,0,0],
            [520,380,290,90,1,4],
            [935,685,520,160,1,6],
            [1685,1230,940,290,2,8],
            [3035,2215,1690,525,2,10],
            [5460,3990,3045,945,2,12]
        ],
        [//brickyardCost gid = 6
            [0,0,0,0,0,0],
            [440,480,320,50,1,3],
            [790,865,575,90,1,5],
            [1425,1555,1035,160,2,7],
            [2565,2800,1865,290,2,9],
            [4620,5040,3360,525,2,11]
        ],
        [//ironFoundryCost gid = 7
            [0,0,0,0,0,0],
            [200,450,510,120,1,6],
            [360,810,920,215,1,9],
            [650,1460,1650,390,2,12],
            [1165,2625,2975,700,2,15],
            [2100,4725,5355,1260,2,18]
        ],
        [//grainMillCost gid = 8
            [0,0,0,0,0,0],
            [500,440,380,1240,1,3],
            [900,790,685,2230,1,5],
            [1620,1425,1230,4020,2,7],
            [2915,2565,2215,7230,2,9],
            [5250,4620,3990,13015,2,11]
        ],
        [//bakeryCost gid = 9
            [0,0,0,0,0,0],
            [1200,1480,870,1600,1,4],
            [2160,2665,1565,2880,1,6],
            [3890,4795,2820,5185,2,8],
            [7000,8630,5075,9330,2,10],
            [12595,15535,9135,16795,2,12]
        ],
        [//warehouseCost gid = 10
            [0,0,0,0,0,0],
            [130,160,90,40,1,1],
            [165,205,115,50,1,2],
            [215,260,145,65,2,3],
            [275,335,190,85,2,4],
            [350,430,240,105,2,5],
            [445,550,310,135,3,6],
            [570,705,395,175,4,7],
            [730,900,505,225,4,8],
            [935,1155,650,290,5,9],
            [1200,1475,830,370,6,10],//10
            [1535,1890,1065,470,7,12],
            [1965,2420,1360,605,9,14],
            [2515,3095,1740,775,11,16],
            [3220,3960,2230,990,13,18],
            [4120,5070,2850,1270,15,20],
            [5275,6490,3650,1625,18,22],
            [6750,8310,4675,2075,22,24],
            [8640,10635,5980,2660,27,26],
            [11060,13610,7655,3405,32,28],
            [14155,17420,9800,4355,38,30]//20
        ],
        [//granaryCost gid = 11
            [0,0,0,0,0,0],
            [80,100,70,20,1,1],
            [100,130,90,25,1,2],
            [130,165,115,35,2,3],
            [170,210,145,40,2,4],
            [215,270,190,55,2,5],
            [275,345,240,70,3,6],
            [350,440,310,90,4,7],
            [450,565,395,115,4,8],
            [575,720,505,145,5,9],
            [740,920,645,185,6,10],//10
            [945,1180,825,235,7,12],
            [1210,1510,1060,300,9,14],
            [1545,1935,1355,385,11,16],
            [1980,2475,1735,495,13,18],
            [2535,3170,2220,635,15,20],
            [3245,4055,2840,810,18,22],
            [4155,5190,3635,1040,22,24],
            [5315,6645,4650,1330,27,26],
            [6805,8505,5955,1700,32,28],
            [8710,10890,7620,2180,38,30]//20
        ],
        [//blacksmithCost gid = 12
            [0,0,0,0,0,0],
            [170,200,380,130,2,4],
            [220,255,485,165,3,6],
            [280,330,625,215,3,8],
            [355,420,795,275,4,10],
            [455,535,1020,350,5,12],
            [585,685,1305,445,6,15],
            [750,880,1670,570,7,18],
            [955,1125,2140,730,9,21],
            [1225,1440,2740,935,10,24],
            [1570,1845,3505,1200,12,27],//10
            [2005,2360,4485,1535,15,30],
            [2570,3020,5740,1965,18,33],
            [3290,3870,7350,2515,21,36],
            [4210,4950,9410,3220,26,39],
            [5390,6340,12045,4120,31,42],
            [6895,8115,15415,5275,37,46],
            [8825,10385,19730,6750,44,50],
            [11300,13290,25255,8640,53,54],
            [14460,17015,32325,11060,64,58],
            [18510,21780,41380,14155,77,62]//20
        ],
        [//armouryCost gid = 13
            [0,0,0,0,0,0],
            [130,210,410,130,2,4],
            [165,270,525,165,3,6],
            [215,345,670,215,3,8],
            [275,440,860,275,4,10],
            [350,565,1100,350,5,12],
            [445,720,1410,445,6,15],
            [570,925,1805,570,7,18],
            [730,1180,2310,730,9,21],
            [935,1515,2955,935,10,24],
            [1200,1935,3780,1200,12,27],//10
            [1535,2480,4840,1535,15,30],
            [1965,3175,6195,1965,18,33],
            [2515,4060,7930,2515,21,36],
            [3220,5200,10150,3220,26,39],
            [4120,6655,12995,4120,31,42],
            [5275,8520,16630,5275,37,46],
            [6750,10905,21290,6750,44,50],
            [8640,13955,27250,8640,53,54],
            [11060,17865,34880,11060,64,58],
            [14155,22865,44645,14155,77,62]//20
        ],
        [//tournamentSquareCost gid = 14
            [0,0,0,0,0,0],
            [1750,2250,1530,240,1,1],
            [2240,2880,1960,305,1,2],
            [2865,3685,2505,395,2,3],
            [3670,4720,3210,505,2,4],
            [4700,6040,4105,645,2,5],
            [6015,7730,5255,825,3,6],
            [7695,9895,6730,1055,4,7],
            [9850,12665,8615,1350,4,8],
            [12610,16215,11025,1730,5,9],
            [16140,20755,14110,2215,6,10],//10
            [20660,26565,18065,2835,7,12],
            [26445,34000,23120,3625,9,14],
            [33850,43520,29595,4640,11,16],
            [43330,55705,37880,5940,13,18],
            [55460,71305,48490,7605,15,20],
            [70990,91270,62065,9735,18,22],
            [90865,116825,79440,12460,22,24],
            [116305,149540,101685,15950,27,26],
            [148875,191410,130160,20415,32,28],
            [190560,245005,166600,26135,38,30]//20
        ],
        [//mainBuildingCost gid = 15
            [0,0,0,0,0,0],
            [70,40,60,20,2,2],
            [90,50,75,25,3,3],
            [115,65,100,35,3,4],
            [145,85,125,40,4,5],
            [190,105,160,55,5,6],
            [240,135,205,70,6,8],
            [310,175,265,90,7,10],
            [395,225,340,115,9,12],
            [505,290,430,145,10,14],
            [645,370,555,185,12,16],//10
            [825,470,710,235,15,18],
            [1060,605,905,300,18,20],
            [1355,775,1160,385,21,22],
            [1735,990,1485,495,26,24],
            [2220,1270,1900,635,31,26],
            [2840,1625,2435,810,37,29],
            [3635,2075,3115,1040,44,32],
            [4650,2660,3990,1330,53,35],
            [5955,3405,5105,1700,64,38],
            [7620,4355,6535,2180,77,41]//20
        ],
        [//rallyPointCost gid = 16
            [0,0,0,0,0,0],
            [110,160,90,70,1,1],
            [140,205,115,90,1,2],
            [180,260,145,115,2,3],
            [230,335,190,145,2,4],
            [295,430,240,190,2,5],
            [380,550,310,240,3,6],
            [485,705,395,310,4,7],
            [620,900,505,395,4,8],
            [795,1155,650,505,5,9],
            [1015,1475,830,645,6,10],//10
            [1300,1890,1065,825,7,12],
            [1660,2420,1360,1060,9,14],
            [2130,3095,1740,1355,11,16],
            [2725,3960,2230,1735,13,18],
            [3485,5070,2850,2220,15,20],
            [4460,6490,3650,2840,18,22],
            [5710,8310,4675,3635,22,24],
            [7310,10635,5980,4650,27,26],
            [9360,13610,7655,5955,32,28],
            [11980,17420,9800,7620,38,30]//20
        ],
        [//marketplaceCost gid = 17
            [0,0,0,0,0,0],
            [80,70,120,70,4,4],
            [100,90,155,90,4,6],
            [130,115,195,115,5,8],
            [170,145,250,145,6,10],
            [215,190,320,190,7,12],
            [275,240,410,240,9,15],
            [350,310,530,310,11,18],
            [450,395,675,395,13,21],
            [575,505,865,505,15,24],
            [740,645,1105,645,19,27],//10
            [945,825,1415,825,22,30],
            [1210,1060,1815,1060,27,33],
            [1545,1355,2320,1355,32,38],
            [1980,1735,2970,1735,39,41],
            [2535,2220,3805,2220,46,44],
            [3245,2840,4870,2840,55,48],
            [4155,3635,6230,3635,67,52],
            [5315,4650,7975,4650,80,56],
            [6805,5955,10210,5955,96,60],
            [8710,7620,13065,7620,115,64]//20
        ],
        [//embassyCost gid = 18
            [0,0,0,0,0,0],
            [180,130,150,80,5,3],
            [230,165,190,100,6,5],
            [295,215,245,130,7,7],
            [375,275,315,170,8,9],
            [485,350,405,215,10,11],
            [620,445,515,275,12,13],
            [790,570,660,350,14,15],
            [1015,730,845,450,17,17],
            [1295,935,1080,575,21,19],
            [1660,1200,1385,740,25,21],//10
            [2125,1535,1770,945,30,24],
            [2720,1965,2265,1210,36,27],
            [3480,2515,2900,1545,43,30],
            [4455,3220,3715,1980,51,33],
            [5705,4120,4755,2535,62,36],
            [7300,5275,6085,3245,74,39],
            [9345,6750,7790,4155,89,42],
            [11965,8640,9970,5315,106,45],
            [15315,11060,12760,6805,128,48],
            [19600,14155,16335,8710,153,51]//20
        ],
        [//barracksCost gid = 19
            [0,0,0,0,0,0],
            [210,140,260,120,1,4],
            [270,180,335,155,1,6],
            [345,230,425,195,2,8],
            [440,295,545,250,2,10],
            [565,375,700,320,2,12],
            [720,480,895,410,3,15],
            [925,615,1145,530,4,18],
            [1180,790,1465,675,4,21],
            [1515,1010,1875,865,5,24],
            [1935,1290,2400,1105,6,27],//10
            [2480,1655,3070,1415,7,30],
            [3175,2115,3930,1815,9,33],
            [4060,2710,5030,2320,11,36],
            [5200,3465,6435,2970,13,39],
            [6655,4435,8240,3805,15,42],
            [8520,5680,10545,4870,18,46],
            [10905,7270,13500,6230,22,50],
            [13955,9305,17280,7975,27,54],
            [17865,11910,22120,10210,32,58],
            [22865,15245,28310,13065,38,62]//20
        ],
        [//stableCost gid = 20
            [0,0,0,0,0,0],
            [260,140,220,100,2,5],
            [335,180,280,130,3,8],
            [425,230,360,165,3,11],
            [545,295,460,210,4,14],
            [700,375,590,270,5,17],
            [895,480,755,345,6,20],
            [1145,615,970,440,7,23],
            [1465,790,1240,565,9,26],
            [1875,1010,1585,720,10,29],
            [2400,1290,2030,920,12,32],//10
            [3070,1655,2595,1180,15,36],
            [3930,2115,3325,1510,18,40],
            [5030,2710,4255,1935,21,44],
            [6435,3465,5445,2475,26,48],
            [8240,4435,6970,3170,31,52],
            [10545,5680,8925,4055,37,56],
            [13500,7270,11425,5190,44,60],
            [17280,9305,14620,6645,53,64],
            [22120,11910,18715,8505,64,68],
            [28310,15245,23955,10890,77,72]//20
        ],
        [//workshopCost gid = 21
            [0,0,0,0,0,0],
            [460,510,600,320,4,3],
            [590,655,770,410,4,5],
            [755,835,985,525,5,7],
            [965,1070,1260,670,6,9],
            [1235,1370,1610,860,7,11],
            [1580,1750,2060,1100,9,13],
            [2025,2245,2640,1405,11,15],
            [2590,2870,3380,1800,13,17],
            [3315,3675,4325,2305,15,19],
            [4245,4705,5535,2950,19,21],//10
            [5430,6020,7085,3780,22,24],
            [6950,7705,9065,4835,27,27],
            [8900,9865,11605,6190,32,30],
            [11390,12625,14855,7925,39,33],
            [14580,16165,19015,10140,46,36],
            [18660,20690,24340,12980,55,39],
            [23885,26480,31155,16615,67,42],
            [30570,33895,39875,21270,80,45],
            [39130,43385,51040,27225,96,48],
            [50090,55535,65335,34845,115,51]//20
        ],
        [//academyCost gid = 22
            [0,0,0,0,0,0],
            [220,160,90,40,5,4],
            [280,205,115,50,6,6],
            [360,260,145,65,7,8],
            [460,335,190,85,8,10],
            [590,430,240,105,10,12],
            [755,550,310,135,12,15],
            [970,705,395,175,14,18],
            [1240,900,505,225,17,21],
            [1585,1155,650,290,21,24],
            [2030,1475,830,370,25,27],//10
            [2595,1890,1065,470,30,30],
            [3325,2420,1360,605,36,33],
            [4255,3095,1740,775,43,36],
            [5445,3960,2230,990,51,39],
            [6970,5070,2850,1270,62,42],
            [8925,6490,3650,1625,74,46],
            [11425,8310,4675,2075,89,50],
            [14620,10635,5980,2660,106,54],
            [18715,13610,7655,3405,128,58],
            [23955,17420,9800,4355,153,62]//20
        ],
        [//crannyCost gid = 23
            [0,0,0,0,0,0],
            [40,50,30,10,1,0],
            [50,65,40,15,1,0],
            [65,80,50,15,2,0],
            [85,105,65,20,2,0],
            [105,135,80,25,2,0],
            [135,170,105,35,3,1],
            [175,220,130,45,4,2],
            [225,280,170,55,4,3],
            [290,360,215,70,5,4],
            [370,460,275,90,6,5]//10
        ],
        [//townhallCost gid = 24
            [0,0,0,0,0,0],
            [1250,1110,1260,600,6,4],
            [1600,1420,1615,770,7,6],
            [2050,1820,2065,985,9,8],
            [2620,2330,2640,1260,10,10],
            [3355,2980,3380,1610,12,12],
            [4295,3815,4330,2060,15,15],
            [5500,4880,5540,2640,18,18],
            [7035,6250,7095,3380,21,21],
            [9005,8000,9080,4325,26,24],
            [11530,10240,11620,5535,31,27],//10
            [14755,13105,14875,7085,37,30],
            [18890,16775,19040,9065,45,33],
            [24180,21470,24370,11605,53,36],
            [30950,27480,31195,14855,64,39],
            [39615,35175,39930,19015,77,42],
            [50705,45025,51110,24340,92,46],
            [64905,57635,65425,31155,111,50],
            [83075,73770,83740,39875,133,54],
            [106340,94430,107190,51040,160,58],
            [136115,120870,137200,65335,192,62]//20
        ],
        [//residenceCost gid = 25
            [0,0,0,0,0,0],
            [580,460,350,180,2,1],
            [740,590,450,230,3,2],
            [950,755,575,295,3,3],
            [1215,965,735,375,4,4],
            [1555,1235,940,485,5,5],
            [1995,1580,1205,620,6,6],
            [2550,2025,1540,790,7,7],
            [3265,2590,1970,1015,9,8],
            [4180,3315,2520,1295,11,9],
            [5350,4245,3230,1660,12,10],//10
            [6845,5430,4130,2125,15,12],
            [8765,6950,5290,2720,18,14],
            [11220,8900,6770,3480,21,16],
            [14360,11390,8665,4455,26,18],
            [18380,14580,11090,5705,31,20],
            [23530,18660,14200,7300,37,22],
            [30115,23885,18175,9345,44,24],
            [38550,30570,23260,11965,53,26],
            [49340,39130,29775,15315,64,28],
            [63155,50090,38110,19600,77,30]//20
        ],
        [//palaceCost gid = 26
            [0,0,0,0,0,0],
            [550,800,750,250,6,1],
            [705,1025,960,320,7,2],
            [900,1310,1230,410,9,3],
            [1155,1680,1575,525,10,4],
            [1475,2145,2015,670,12,5],
            [1890,2750,2575,860,15,6],
            [2420,3520,3300,1100,18,7],
            [3095,4505,4220,1405,21,8],
            [3965,5765,5405,1800,26,9],
            [5075,7380,6920,2305,31,10],//10
            [6495,9445,8855,2950,37,12],
            [8310,12090,11335,3780,45,14],
            [10640,15475,14505,4835,53,16],
            [13615,19805,18570,6190,64,18],
            [17430,25355,23770,7925,77,20],
            [22310,32450,30425,10140,92,22],
            [28560,41540,38940,12980,111,24],
            [36555,53170,49845,16615,133,26],
            [46790,68055,63805,21270,160,28],
            [59890,87110,81670,27225,192,30]//20
        ],
        [//treasuryCost gid = 27
            [0,0,0,0,0,0],
            [2880,2740,2580,990,7,4],
            [3630,3450,3250,1245,9,6],
            [4570,4350,4095,1570,10,8],
            [5760,5480,5160,1980,12,10],
            [7260,6905,6505,2495,15,12],
            [9145,8700,8195,3145,18,15],
            [11525,10965,10325,3960,21,18],
            [14520,13815,13010,4990,26,21],
            [18295,17405,16390,6290,31,24],
            [23055,21930,20650,7925,37,27],//10
            [29045,27635,26020,9985,45,30],
            [36600,34820,32785,12580,53,33],
            [46115,43875,41310,15850,64,36],
            [58105,55280,52050,19975,77,39],
            [73210,69655,65585,25165,92,42],
            [92245,87760,82640,31710,111,46],
            [116230,110580,104125,39955,133,50],
            [146450,139330,131195,50340,160,54],
            [184530,175560,165305,63430,192,58],
            [232505,221205,208285,79925,230,62]//20
        ],
        [//tradeOfficeCost gid = 28
            [0,0,0,0,0,0],
            [1400,1330,1200,400,4,3],
            [1790,1700,1535,510,4,5],
            [2295,2180,1965,655,5,7],
            [2935,2790,2515,840,6,9],
            [3760,3570,3220,1075,7,11],
            [4810,4570,4125,1375,9,13],
            [6155,5850,5280,1760,11,15],
            [7880,7485,6755,2250,13,17],
            [10090,9585,8645,2880,15,19],
            [12915,12265,11070,3690,19,21],//10
            [16530,15700,14165,4720,22,24],
            [21155,20100,18135,6045,27,27],
            [27080,25725,23210,7735,32,30],
            [34660,32930,29710,9905,39,33],
            [44370,42150,38030,12675,46,36],
            [56790,53950,48680,16225,55,39],
            [72690,69060,62310,20770,67,42],
            [93045,88395,79755,26585,80,45],
            [119100,113145,102085,34030,96,48],
            [152445,144825,130670,43555,115,51]//20
        ],
        [//greatBarrackCost gid = 29
            [0,0,0,0,0,0],
            [630,420,780,360,1,4],
            [805,540,1000,460,1,6],
            [1030,690,1280,590,2,8],
            [1320,880,1635,755,2,10],
            [1690,1125,2095,965,2,12],
            [2165,1445,2680,1235,3,15],
            [2770,1845,3430,1585,4,18],
            [3545,2365,4390,2025,4,21],
            [4540,3025,5620,2595,5,24],
            [5810,3875,7195,3320,6,27],//10
            [7440,4960,9210,4250,7,30],
            [9520,6345,11785,5440,9,33],
            [12185,8125,15085,6965,11,36],
            [15600,10400,19310,8915,13,39],
            [19965,13310,24720,11410,15,42],
            [25555,17035,31640,14605,18,46],
            [32710,21810,40500,18690,22,50],
            [41870,27915,51840,23925,27,54],
            [53595,35730,66355,30625,32,58],
            [68600,45735,84935,39200,38,62]//20
        ],
        [//greatStableCost gid = 30
            [0,0,0,0,0,0],
            [780,420,660,300,2,5],
            [1000,540,845,385,3,8],
            [1280,690,1080,490,3,11],
            [1635,880,1385,630,4,14],
            [2095,1125,1770,805,5,17],
            [2680,1445,2270,1030,6,20],
            [3430,1845,2905,1320,7,23],
            [4390,2365,3715,1690,9,26],
            [5620,3025,4755,2160,10,29],
            [7195,3875,6085,2765,12,32],//10
            [9210,4960,7790,3540,15,36],
            [11785,6345,9975,4535,18,40],
            [15085,8125,12765,5805,21,44],
            [19310,10400,16340,7430,26,48],
            [24720,13310,20915,9505,31,52],
            [31640,17035,26775,12170,37,56],
            [40500,21810,34270,15575,44,60],
            [51840,27915,43865,19940,53,64],
            [66355,35730,56145,25520,64,68],
            [84935,45735,71870,32665,77,72]//20
        ],
        [//citywallCost gid = 31
            [0,0,0,0,0,0],
            [70,90,170,70,1,0],
            [90,115,220,90,1,0],
            [115,145,280,115,2,0],
            [145,190,355,145,2,0],
            [190,240,455,190,2,0],
            [240,310,585,240,3,1],
            [310,395,750,310,4,2],
            [395,505,955,395,4,3],
            [505,650,1225,505,5,4],
            [645,830,1570,645,6,5],//10
            [825,1065,2005,825,7,6],
            [1060,1360,2570,1060,9,7],
            [1355,1740,3290,1355,11,8],
            [1735,2230,4210,1735,13,9],
            [2220,2850,5390,2220,15,10],
            [2840,3650,6895,2840,18,12],
            [3635,4675,8825,3635,22,14],
            [4650,5980,11300,4650,27,16],
            [5955,7655,14460,5955,32,18],
            [7620,9800,18510,7620,38,20]//20
        ],
        [//earthwallCost gid = 32
            [0,0,0,0,0,0],
            [120,200,0,80,1,0],
            [155,255,0,100,1,0],
            [195,330,0,130,2,0],
            [250,420,0,170,2,0],
            [320,535,0,215,2,0],
            [410,685,0,275,3,1],
            [530,880,0,350,4,2],
            [675,1125,0,450,4,3],
            [865,1440,0,575,5,4],
            [1105,1845,0,740,6,5],//10
            [1415,2360,0,945,7,6],
            [1815,3020,0,1210,9,7],
            [2320,3870,0,1545,11,8],
            [2970,4950,0,1980,13,9],
            [3805,6340,0,2535,15,10],
            [4870,8115,0,3245,18,12],
            [6230,10385,0,4155,22,14],
            [7975,13290,0,5315,27,16],
            [10210,17015,0,6805,32,18],
            [13065,21780,0,8710,38,20]//20
        ],
        [//palisadeCost gid = 33
            [0,0,0,0,0,0],
            [160,100,80,60,1,0],
            [205,130,100,75,1,0],
            [260,165,130,100,2,0],
            [335,210,170,125,2,0],
            [430,270,215,160,2,0],
            [550,345,275,205,3,1],
            [705,440,350,265,4,2],
            [900,565,450,340,4,3],
            [1155,720,575,430,5,4],
            [1475,920,740,555,6,5],//10
            [1890,1180,945,710,7,6],
            [2420,1510,1210,905,9,7],
            [3095,1935,1545,1160,11,8],
            [3960,2475,1980,1485,13,9],
            [5070,3170,2535,1900,15,10],
            [6490,4055,3245,2435,18,12],
            [8310,5190,4155,3115,22,14],
            [10635,6645,5315,3990,27,16],
            [13610,8505,6805,5105,32,18],
            [17420,10890,8710,6535,38,20]//20
        ],
        [//stonemasonCost gid = 34
            [0,0,0,0,0,0],
            [155,130,125,70,1,2],
            [200,165,160,90,1,3],
            [255,215,205,115,2,4],
            [325,275,260,145,2,5],
            [415,350,335,190,2,6],
            [535,445,430,240,3,8],
            [680,570,550,310,4,10],
            [875,730,705,395,4,12],
            [1115,935,900,505,5,14],
            [1430,1200,1155,645,6,16],//10
            [1830,1535,1475,825,7,18],
            [2340,1965,1890,1060,9,20],
            [3000,2515,2420,1355,11,22],
            [3840,3220,3095,1735,13,24],
            [4910,4120,3960,2220,15,26],
            [6290,5275,5070,2840,18,29],
            [8050,6750,6490,3635,22,32],
            [10300,8640,8310,4650,27,35],
            [13185,11060,10635,5955,32,38],
            [16880,14155,13610,7620,38,41]//20
        ],
        [//breweryCost gid = 35
            [0,0,0,0,0,0],
            [1460,930,1250,1740,5,6],
            [2045,1300,1750,2435,6,9],
            [2860,1825,2450,3410,7,12],
            [4005,2550,3430,4775,8,15],
            [5610,3575,4800,6685,10,18],
            [7850,5000,6725,9360,12,22],
            [10995,7000,9410,13100,14,26],
            [15390,9805,13175,18340,17,30],
            [21545,13725,18445,25680,21,34],
            [30165,19215,25825,35950,25,38]//10
        ],
        [//trapperCost gid = 36
            [0,0,0,0,0,0],
            [100,100,100,100,1,4],
            [130,130,130,130,1,6],
            [165,165,165,165,2,8],
            [210,210,210,210,2,10],
            [270,270,270,270,2,12],
            [345,345,345,345,3,15],
            [440,440,440,440,4,18],
            [565,565,565,565,4,21],
            [720,720,720,720,5,24],
            [920,920,920,920,6,27],//10
            [1180,1180,1180,1180,7,30],
            [1510,1510,1510,1510,9,33],
            [1935,1935,1935,1935,11,36],
            [2475,2475,2475,2475,13,39],
            [3170,3170,3170,3170,15,42],
            [4055,4055,4055,4055,18,46],
            [5190,5190,5190,5190,22,50],
            [6645,6645,6645,6645,27,54],
            [8505,8505,8505,8505,32,58],
            [10890,10890,10890,10890,38,62]//20
        ],
        [//herosMansionCost gid = 37
            [0,0,0,0,0,0],
            [700,670,700,240,1,2],
            [930,890,930,320,1,3],
            [1240,1185,1240,425,2,4],
            [1645,1575,1645,565,2,5],
            [2190,2095,2190,750,2,6],
            [2915,2790,2915,1000,3,8],
            [3875,3710,3875,1330,4,10],
            [5155,4930,5155,1765,4,12],
            [6855,6560,6855,2350,5,14],
            [9115,8725,9115,3125,6,16],//10
            [12125,11605,12125,4155,7,18],
            [16125,15435,16125,5530,9,20],
            [21445,20525,21445,7350,11,22],
            [28520,27300,28520,9780,13,24],
            [37935,36310,37935,13005,15,24],
            [50450,48290,50450,17300,18,27],
            [67100,64225,67100,23005,22,30],
            [89245,85420,89245,30600,27,33],
            [118695,113605,118695,40695,32,36],
            [157865,151095,157865,54125,37,39]//20
        ],
        [//greatWarehouseCost gid = 38
            [0,0,0,0,0,0,0],
            [650,800,450,200,1,1],
            [830,1025,575,255,1,2],
            [1065,1310,735,330,2,3],
            [1365,1680,945,420,2,4],
            [1745,2145,1210,535,2,5],
            [2235,2750,1545,685,3,6],
            [2860,3520,1980,880,4,7],
            [3660,4505,2535,1125,4,8],
            [4685,5765,3245,1440,5,9],
            [5995,7380,4150,1845,6,10],//10
            [7675,9445,5315,2360,7,12],
            [9825,12090,6800,3020,9,14],
            [12575,15475,8705,3870,11,16],
            [16095,19805,11140,4950,13,18],
            [20600,25355,14260,6340,15,20],
            [26365,32450,18255,8115,18,22],
            [33750,41540,23365,10385,22,24],
            [43200,53170,29910,13290,27,26],
            [55295,68055,38280,17015,32,28],
            [70780,87110,49000,21780,38,30]//20
        ],
        [//greatGranaryCost gid = 39
            [0,0,0,0,0,0],
            [400,500,350,100,1],
            [510,640,450,130,1,2],
            [655,820,575,165,2,3],
            [840,1050,735,210,2,4],
            [1075,1340,940,270,2,5],
            [1375,1720,1205,345,3,6],
            [1760,2200,1540,440,4,7],
            [2250,2815,1970,565,4,8],
            [2880,3605,2520,720,5,9],
            [3690,4610,3230,920,6,10],//10
            [4720,5905,4130,1180,7,12],
            [6045,7555,5290,1510,9,14],
            [7735,9670,6770,1935,11,16],
            [9905,12380,8665,2475,13,18],
            [12675,15845,11090,3170,15,20],
            [16225,20280,14200,4055,18,22],
            [20770,25960,18175,5190,22,24],
            [26585,33230,23260,6645,27,26],
            [34030,42535,29775,8505,32,28],
            [43555,54445,38110,10890,38,30]//20
        ],
        [//WWCost gid = 40
            [0,0,0,0,0,0],
            [66700,69050,72200,13200,0,1],
            [68535,70950,74185,13565,0,2],
            [70420,72900,76225,13935,0,3],
            [72355,74905,78320,14320,0,4],
            [74345,76965,80475,14715,0,5],
            [76390,79080,82690,15120,0,6],
            [78490,81255,84965,15535,0,7],
            [80650,83490,87300,15960,0,8],
            [82865,85785,89700,16400,0,9],
            [85145,88145,92165,16850,0,10],//10
            [87485,90570,94700,17315,0,12],
            [89895,93060,97305,17790,0,14],
            [92365,95620,99980,18280,0,16],
            [94905,98250,102730,18780,0,18],
            [97515,100950,105555,19300,0,20],
            [100195,103725,108460,19830,0,22],
            [102950,106580,111440,20375,0,24],
            [105785,109510,114505,20935,0,26],
            [108690,112520,117655,21510,0,28],
            [111680,115615,120890,22100,0,30],//20
            [114755,118795,124215,22710,0,33],
            [117910,122060,127630,23335,0,36],
            [121150,125420,131140,23975,0,39],
            [124480,128870,134745,24635,0,42],
            [127905,132410,138455,25315,0,45],
            [131425,136055,142260,26010,0,48],
            [135035,139795,146170,26725,0,51],
            [138750,143640,150190,27460,0,54],
            [142565,147590,154320,28215,0,57],
            [146485,151650,158565,28990,0,60],//30
            [150515,155820,162925,29785,0,64],
            [154655,160105,167405,30605,0,68],
            [158910,164505,172010,31450,0,72],
            [163275,169030,176740,32315,0,76],
            [167770,173680,181600,33200,0,80],
            [172380,178455,186595,34115,0,84],
            [177120,183360,191725,35055,0,88],
            [181995,188405,197000,36015,0,92],
            [186995,193585,202415,37005,0,96],
            [192140,198910,207985,38025,0,100],//40
            [197425,204380,213705,39070,0,105],
            [202855,210000,219580,40145,0,110],
            [208430,215775,225620,41250,0,115],
            [214165,221710,231825,42385,0,120],
            [220055,227805,238200,43550,0,125],
            [226105,234070,244750,44745,0,130],
            [232320,240505,251480,45975,0,135],
            [238710,247120,258395,47240,0,140],
            [245275,253915,265500,48540,0,145],
            [252020,260900,272800,49875,0,150],//50
            [258950,268075,280305,51245,0,156],
            [266070,275445,288010,52655,0,162],
            [273390,283020,295930,54105,0,168],
            [280905,290805,304070,55590,0,174],
            [288630,298800,312430,57120,0,180],
            [296570,307020,321025,58690,0,186],
            [304725,315460,329850,60305,0,192],
            [313105,324135,338925,61965,0,198],
            [321715,333050,348245,63670,0,204],
            [330565,342210,357820,65420,0,210],//60
            [339655,351620,367660,67220,0,217],
            [348995,361290,377770,69065,0,224],
            [358590,371225,388160,70965,0,231],
            [368450,381435,398835,72915,0,238],
            [378585,391925,409800,74920,0,245],
            [388995,402700,421070,76985,0,252],
            [399695,413775,432650,79100,0,259],
            [410685,425155,444550,81275,0,266],
            [421980,436845,456775,83510,0,273],
            [433585,448860,469335,85805,0,280],//70
            [445505,461205,482240,88165,0,288],
            [457760,473885,495505,90590,0,296],
            [470345,486920,509130,93080,0,304],
            [483280,500310,523130,95640,0,312],
            [496570,514065,537520,98270,0,320],
            [510225,528205,552300,100975,0,328],
            [524260,542730,567490,103750,0,336],
            [538675,557655,583095,106605,0,344],
            [553490,572990,599130,109535,0,352],
            [568710,588745,615605,112550,0,360],//80
            [584350,604935,632535,115645,0,369],
            [600420,621575,649930,118825,0,378],
            [616930,638665,667800,122090,0,387],
            [633895,656230,686165,125450,0,396],
            [651330,674275,705035,128900,0,405],
            [669240,692820,724425,132445,0,414],
            [687645,711870,744345,136085,0,423],
            [706555,731445,764815,139830,0,432],
            [725985,751560,785850,143675,0,441],
            [745950,772230,807460,147625,0,450],//90
            [766460,793465,829665,151685,0,460],
            [787540,815285,852480,155855,0,470],
            [809195,837705,875920,160140,0,480],
            [831450,860745,900010,164545,0,490],
            [854315,884415,924760,169070,0,500],
            [877810,908735,950190,173720,0,510],
            [901950,933725,976320,178495,0,520],
            [926750,959405,1000000,183405,0,530],
            [952235,985785,1000000,188450,0,540],
            [1000000,1000000,1000000,193630,0,550]//100
        ],
        [//horsedtCost gid = 41
            [0,0,0,0,0,0],
            [780,420,660,540,4,5],
            [1000,540,845,690,4,8],
            [1280,690,1080,885,5,11],
            [1635,880,1385,1130,6,14],
            [2095,1125,1770,1450,7,17],
            [2680,1445,2270,1855,9,20],
            [3430,1845,2905,2375,11,23],
            [4390,2365,3715,3040,13,26],
            [5620,3025,4755,3890,15,29],
            [7195,3875,6085,4980,19,31],//10
            [9210,4960,7790,6375,22,35],
            [11785,6345,9975,8160,27,39],
            [15085,8125,12765,10445,32,43],
            [19310,10400,16340,13370,39,47],
            [24720,13310,20915,17115,46,51],
            [31640,17035,26775,21905,55,55],
            [40500,21810,34270,28040,67,59],
            [51840,27915,43865,35890,80,63],
            [66355,35730,56145,45940,96,67],
            [84935,45735,71870,58800,115,71]//20
        ]
    ];


//Training cost for each unit (4), load capacity (1), attack power (1), def power infantery (1), def power cavalery (1), speed (1) - for normal servers, crop consumption(1)
var uc = new Array();
//Romans
uc[1] = [120,100,150,30,50,40,35,50,6,1];//Legionnaire
uc[2] = [100,130,160,70,20,30,65,35,5,1];//Praetorian
uc[3] = [150,160,210,80,50,70,40,25,7,1];//Imperian
uc[4] = [140,160,20,40,0,0,20,10,16,2];//Equites legati
uc[5] = [550,440,320,100,100,120,65,50,14,3];//Equites imperatoris
uc[6] = [550,640,800,180,70,180,80,105,10,4];//Equites cesaris
uc[7] = [900,360,500,70,0,60,30,75,4,3];//Battering ram
uc[8] = [950,1350,600,90,0,75,60,10,3,6];//Fire catapult
uc[9] = [30750,27200,45000,37500,0,50,40,30,4,5];//Senator
uc[10] = [5800,5300,7200,5500,3000,0,80,80,5,1];//Settler
//Teutons
uc[11] = [95,75,40,40,60,40,20,5,7,1];//Club swinger
uc[12] = [145,70,85,40,40,10,35,60,7,1];//Spearman
uc[13] = [130,120,170,70,50,60,30,30,6,1];//Axeman
uc[14] = [160,100,50,50,0,0,10,5,9,1];//Scout
uc[15] = [370,270,290,75,110,55,100,40,10,2];//Paladin
uc[16] = [450,515,480,80,80,150,50,75,9,3];//Teutonic knight
uc[17] = [1000,300,350,70,0,65,30,80,4,3];//Ram
uc[18] = [900,1200,600,60,0,50,60,10,3,6];//Catapult
uc[19] = [35500,26600,25000,27200,0,40,60,40,4,4];//Chief
uc[20] = [7200,5500,5800,6500,3000,10,80,80,5,1];//Settler
//Gauls
uc[21] = [100,130,55,30,35,15,40,50,7,1];//Phalanx
uc[22] = [140,150,185,60,45,65,35,20,6,1];//Swordsman
uc[23] = [170,150,20,40,0,0,20,10,17,2];//Pathfinder
uc[24] = [350,450,230,60,75,90,25,40,19,2];//Theutates thunder
uc[25] = [360,330,280,120,35,45,115,55,16,2];//Druidrider
uc[26] = [500,620,675,170,65,140,50,165,13,3];//Haeduan
uc[27] = [950,555,330,75,0,50,30,105,4,3];//Ram
uc[28] = [960,1450,630,90,0,70,45,10,3,6];//Trebuchet
uc[29] = [30750,45400,31000,37500,0,40,50,50,5,4];//Chieftain
uc[30] = [5500,7000,5300,4900,3000,0,80,80,5,1];//Settler
//Nature
uc[31] = [0,0,0,0,0,10,25,20,0,1];//Rat
uc[32] = [0,0,0,0,0,20,35,40,0,1];//Spider
uc[33] = [0,0,0,0,0,60,40,60,0,1];//Snake
uc[34] = [0,0,0,0,0,80,66,50,0,1];//Bat
uc[35] = [0,0,0,0,0,50,70,33,0,2];//Wild boar
uc[36] = [0,0,0,0,0,100,80,70,0,2];//Wolf
uc[37] = [0,0,0,0,0,250,140,200,0,3];//Bear
uc[38] = [0,0,0,0,0,450,380,240,0,3];//Crocodile
uc[39] = [0,0,0,0,0,200,170,250,0,3];//Tiger
uc[40] = [0,0,0,0,0,600,440,520,0,5];//Elephant
//Natarian - fr3nchlover
uc[41] = [0,0,0,0,0,20,35,50,0,1];//Pikeman
uc[42] = [0,0,0,0,0,65,30,10,0,1];//Thorned warrior
uc[43] = [0,0,0,0,0,100,90,75,0,1];//Guardsman
uc[44] = [0,0,0,0,0,0,10,0,0,1];//Birds of prey
uc[45] = [0,0,0,0,0,155,80,50,0,2];//Axerider
uc[46] = [0,0,0,0,0,170,140,80,0,3];//Natarian knight
uc[47] = [0,0,0,0,0,250,120,150,0,6];//Warelephant
uc[48] = [0,0,0,0,0,60,45,10,0,5];//Ballista
uc[49] = [0,0,0,0,0,80,50,50,0,0];//Natarian emperor
uc[50] = [0,0,0,0,0,30,40,40,0,0];//Settler
uc[98] = [20,30,10,20,0,0,0,0,0,0];//trap
uc[99] = [20,30,10,20,0,0,0,0,0,0];//trap

}